package com.springcloud.springcloudclient01.com.ded;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/consumer01")
public class Consumer01 {

    public static final Logger logger = LoggerFactory.getLogger(Consumer01.class);

    public static final String applicationName = "springcloud-client-provider";

    @Autowired
    private RestTemplate restTemplate;

    @ResponseBody
    @RequestMapping(value = "/hello")
    public Object hello() {
        logger.info("===============");
        logger.info("====: " + ThreadLocalUtil.get("startTime"));
//        ThreadLocalUtil.remove();
        logger.info("====: " + ThreadLocalUtil.get("loggerTag"));
        Map<String, String> map = new HashMap<>();
        return restTemplate.getForObject("http://" + applicationName+"/provider01/hello", String.class);

    }

    public static void main(String[] args) {
        logger.info("============");
    }

    @ResponseBody
    @RequestMapping(value = "/hello2")
    public Object hello2() {
        return "consumer01---hello";
//        return restTemplate.getForObject("http://" + applicationName+"/provider01/hello", String.class);
    }

    @ResponseBody
    @RequestMapping(value = "/hello3")
    public Object hello3() {
        return "consumer01---hello3";
//        return restTemplate.getForObject("http://" + applicationName+"/provider01/hello", String.class);
    }
}
